Skip to content

[codegen] migrate stdlib/console,date to emitsymbol/emitoperand helpers#647

Merged
cs01 merged 1 commit intomainfrom
step2-wave2-stdlib
Apr 21, 2026
Merged

[codegen] migrate stdlib/console,date to emitsymbol/emitoperand helpers#647
cs01 merged 1 commit intomainfrom
step2-wave2-stdlib

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 21, 2026

Before

stdlib/console.ts and stdlib/date.ts used raw ctx.emit template strings with inline i8* ${...}, double ${...}, @fflush, @stderr operands and symbol sigils.

After

No user-facing change. Internal refactor only. Both files now funnel symbol references through emitSymbol(name, "@") and all typed operands through emitOperand(value, llvmType), matching the pattern established in PR #645 (math/process).

Description

Continues Step 2 of #640. Follows the pilot PR #645 pattern:

  • console.tsprintf/fprintf/fflush calls, @stderr load, %__FetchResponse body load.
  • date.tsgmtime_r/localtime_r/strftime/cs_arena_alloc calls, fdiv/fptosi/sitofp/fadd type operands, struct field loads.

Callers that don't have native builder methods on IGeneratorContext (alloca, sitofp, fptosi) keep their raw ctx.emit form but use emitOperand for operand typing.

Verified: npm run verify:quick green; full bash scripts/self-hosting.sh (stage 0/1/2) green.

@github-actions
Copy link
Copy Markdown
Contributor

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Place
Cold Start 1.0ms 0.9ms 1.2ms 27.3ms 🥇
Fibonacci 0.814s 0.763s 1.561s 3.170s 🥇
Hash Map Lookup 0.096s 0.063s 0.091s 0.126s 🥇
Binary Trees 1.503s 1.310s 2.737s 1.220s 🥈
File I/O 0.123s 0.096s 0.089s 0.213s 🥈
JSON Parse/Stringify 0.035s 0.052s 0.181s 0.136s 🥈
N-Body Simulation 1.672s 2.124s 2.208s 2.391s 🥈
Regex Match 0.016s 0.005s 0.021s 0.004s 🥈
SQLite 0.052s 0.371s 0.498s 0.431s 🥈
Monte Carlo Pi 0.389s 0.410s 0.404s 2.249s 🥉
Quicksort 0.215s 0.246s 0.213s 0.262s 🥉
Sieve of Eratosthenes 0.017s 0.029s 0.020s 0.040s 🥉
String Manipulation 0.008s 0.019s 0.016s 0.037s 🥉
Matrix Multiply 0.613s 1.002s 0.622s 0.359s #4

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.563s 1.096s 0.129s 🥈
Recursive Grep 0.020s 0.011s 0.106s 🥈

@cs01 cs01 merged commit 813def4 into main Apr 21, 2026
13 checks passed
@cs01 cs01 deleted the step2-wave2-stdlib branch April 21, 2026 20:22
cs01 added a commit that referenced this pull request Apr 22, 2026
structured ir builders (emitcall/emitgep/emitbitcast/emitload/emitstore/emitcallvoid)
caused stage2 array-isarray miscompile on ci. revert them to inline emit() per
step 2 wave 3 intent. only emitsymbol/emitoperand wrappers remain, matching
console/date pattern from pr #647.

fixes #649
cs01 added a commit that referenced this pull request Apr 22, 2026
* [codegen] migrate stdlib/crypto to emitsymbol/emitoperand helpers

* scope crypto migration back to emitsymbol/emitoperand only

structured ir builders (emitcall/emitgep/emitbitcast/emitload/emitstore/emitcallvoid)
caused stage2 array-isarray miscompile on ci. revert them to inline emit() per
step 2 wave 3 intent. only emitsymbol/emitoperand wrappers remain, matching
console/date pattern from pr #647.

fixes #649

---------

Co-authored-by: cs01 <cs01@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant